﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using jaysJourney_v01.Common;
using Microsoft.Xna.Framework;
using System.Diagnostics;

namespace jaysJourney_v01.Utils.Network
{
    class LoaderOverlay
    {
        /**
         * MEMBER VARIABLES
         * */

        // From Parents

        private JaysJourneyMain game;
        private SpriteBatch parentSpriteBatch;

        // Common

        private SpriteAnimator loader;
        private Texture2D bg;

        /**
         * METHODS
         * */

        public LoaderOverlay(JaysJourneyMain game, SpriteBatch parentSB)
        {
            this.game = game;
            this.parentSpriteBatch = parentSB;

            this.bg = game.Content.Load<Texture2D>(@"Textures\Messages\1x1");
            this.loader = new SpriteAnimator(parentSB, game.Content.Load<Texture2D>(@"Textures\Preloader\preloader"), 12, 6, 105, 16, 630, 16, true, false);
            this.loader.play();
        }

        // draw loader-overlay

        public void draw(object gameTime)
        {
            Debug.WriteLine("loading");
            this.parentSpriteBatch.Begin();
            // overlay
            this.parentSpriteBatch.Draw(bg, new Rectangle(0, 0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height), Color.White * 0.5f);

            // loader
            this.loader.animate((GameTime)gameTime, new Vector2((game.GraphicsDevice.Viewport.Width / 2) - 52, (game.GraphicsDevice.Viewport.Height / 2) - 8), true);

            this.parentSpriteBatch.End();
        }
    }
}
